package Test28;

import java.math.BigInteger;

//BigInteger类的使用（成员方法）
/*
public BigInteger add(BigInteger val)                       加法
public BigInteger subtract(BigInteger val                   减法
public BigInteger multiply(BigInteger val)                  乘法
public BigInteger divide( BigInteger val)                   除法，获取商
public BigInteger[] divideAndRemainder(BigInteger val)      除法，获取商和余数
public boolean equals(object x)                             比较是否相同
publicBigInteger pow(int exponent)                          次幂
public BigInteger max /min(BigInteger val)                  返回较大值/较小值
public int intValue(BigInteger val)                         转为int类型整数，超出范围数据有误
 */
public class Test13 {
    public static void main(String[] args) {

        //1、创建两个BigInteger对象
        BigInteger bd1 = BigInteger.valueOf(10);
        BigInteger bd2 = BigInteger.valueOf(2);

        //2、加法
        BigInteger bd3 = bd1.add(bd2);
        System.out.println(bd3);

        System.out.println("-----------------");

        //3、除法，获取商和余数
        BigInteger[] arr = bd1.divideAndRemainder(bd2);
        System.out.println(arr.length);
        System.out.println(arr[0]);
        System.out.println(arr[1]);

        System.out.println("-----------------");

        //4、比较是否相同
        boolean result = bd1.equals(bd2);
        System.out.println(result);

        System.out.println("-----------------");

        //5、次幂
        BigInteger bd4 = bd1.pow(2);
        System.out.println(bd4);

        System.out.println("-----------------");

        //6、返回较大值
        BigInteger bd5 = bd1.max(bd2);
        System.out.println(bd5);
        System.out.println(bd5 == bd1);//true
        System.out.println(bd5 == bd2);//false

        System.out.println("-----------------");

        //7、转为int类型和long类型整数，超出范围数据有误
        BigInteger bd6 = BigInteger.valueOf(2147483647);
        int i = bd6.intValue();
        System.out.println(i);

        BigInteger bd7 = BigInteger.valueOf(2147483648L);
        long l = bd7.longValue();
        System.out.println(l);
    }
}
